﻿@{
    ViewBag.Title = "Danh sách lệnh điều xe";
    var url = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/');
}
<script>
    app.controller('CommandController', function ($scope, $compile, $http, service) {
        $scope.load = function (page) {
            if (page === 0 || (page > $scope.pageCount && $scope.pageCount > 0))
                return;

            $scope.checkedList = [];
            $scope.checkedObj = [{}];
            startloading($('#content'));

            var url = '@url' + '@Url.Action("CommandApi", "Api")';
            $http.get(url, {
                params: {
                    pageNumber: page,
                    orderBy: $scope.orderBy,
                    orderDirection: $scope.orderDirection,
                }
            })
                .success(function (data) {
                    service.setCommonData($scope, data, data.Commands);
                    stoploading($('#content'));
                })
                .error(function (data) {
                    stoploading($('#content'));
                    service.showModal($scope, $compile, 'error', data.InnerException.InnerException);
                });
        };

        $scope.setSelected = function (id) {
            service.setSelected($scope, id);
        };

        $scope.check = function (id) {
            $scope.checkedObj[id] = !$scope.checkedObj[id];
        };

        $scope.setSelectedAll = function () {
            service.setSelectedAll($scope);
        };

        $scope.refresh = function (keyCode) {
            if (keyCode == undefined || keyCode === 13)
                $scope.load($scope.pageNumber);
        };

        $scope.clearrefresh = function () {

            $scope.load($scope.pageNumber);
        };

        $scope.add = function () {
            window.location = '@Url.Action("Detail", "Command")';
        };

        $scope.edit = function (id) {
            if (id) {
                window.location = '@Url.Action("Detail", "Command")/' + id;
            } else {
                var selectedObj = service.getLastSelected($scope, $compile, service);
                if (selectedObj != '')
                    window.location = '@Url.Action("Detail", "Command")/' + selectedObj;
            }
        };

        $scope.confirmDelete = function () {
            service.showModal($scope, $compile, 'confirm', 'Bạn có chắc chắn muốn xóa dữ liệu?', 'delete()');
        };

        $scope.delete = function () {
            var deleteObj = service.getSelected($scope);
            if (deleteObj === '') return;

            $scope.checkedList = [];
            $scope.checkedObj = [{}];
            startloading($('#content'));

            var url = '@url' + '@Url.Action("CommandApi", "Api")';
            $http.delete(url, {
                params: {
                    ids: deleteObj,
                    pageNumber: $scope.pageNumber,
                    orderBy: $scope.orderBy,
                    orderDirection: $scope.orderDirection,
                }
            }).success(function (data) {
                service.setCommonData($scope, data, data.Commands);
                stoploading($('#content'));
                service.showModal($scope, $compile, 'notify', 'Xóa thành công các phiếu điều xe có trạng thái mới');
            }).error(function (data) {
                stoploading($('#content'));
                service.showModal($scope, $compile, 'error', data);
            });
        };

        $scope.sort = function (ob) {
            service.setSortingValue($scope, ob);
            $scope.load($scope.pageNumber);
        };

        $scope.statuss = [{}];
        $scope.statuss['N'] = 'Mới';
        $scope.statuss['C'] = 'Hoàn thành';

        $scope.orderBy = 'CommandCode';
        $scope.orderDirection = 'descending';
        $scope.checkedList = [];
        $scope.checkedObj = [{}];
        $scope.load(1);
    });
</script>
<div ng-controller="CommandController">
    @Html.Partial("_PageHeader")
    @Html.Partial("_ListViewHeader")

    <div id="content" class="content row">
        <form role="form" name="form" autocomplete="off">
            <div class="panel-body">
                <div id="search">
                    <div class="row" style="margin-right: 0px">
                        <div class="col-lg-2">
                            @Html.Partial("Control/_Control_TextBox", new Dictionary<string, string>
                    {
                        {"Text", "Mã số phiếu"},
                        {"Model", "commandCode"},
                        {"Name", "commandCode"},
                        {"MaxLength","12"}
                    })
                        </div>
                        <div class="col-lg-2">
                            @Html.Partial("Control/_Control_TextBox", new Dictionary<string, string>
                    {
                        {"Text", "Tài xế"},
                        {"Model", "fullName"},
                        {"Name", "fullName"},
                        {"MaxLength","15"}
                    })
                        </div>
                        <div class="col-lg-2" style="clear: both">
                            @Html.Partial("Control/_Control_Datepicker", new Dictionary<string, string>
                        {
                            {"Text", "Từ ngày"},
                            {"Model", "dateFrom"},
                            {"Name", "dateFrom"}
                        })
                        </div>
                        <div class="col-lg-2">
                            @Html.Partial("Control/_Control_Datepicker", new Dictionary<string, string>
                        {
                            {"Text", "đến"},
                            {"Model", "dateTo"},
                            {"Name", "dateTo"}
                        })
                        </div>
                        @Html.Partial("_Search")
                    </div>
                </div>
                <div class="table-responsive">
                    @Html.Partial("_Toolbar_PagedList")
                    <table id="data" class="table table-striped table-bordered table-hover">
                        <colgroup>
                            <col style="width: 50px" />
                            <col style="width: 100px" />
                            <col />
                            <col style="width: 100px" />
                            <col style="width: 150px" />
                            <col style="width: 100px" />
                            <col style="width: 100px" />
                            <col style="width: 80px" />
                            <col style="width: 80px" />
                            <col style="width: 80px" />
                            <col style="width: 100px" />
                        </colgroup>
                        <thead>
                            <tr>
                                <th>
                                    <div>
                                        <input ng-model="selectedAll" ng-click="setSelectedAll()" style="margin-left: 10px;" class="center" type="checkbox">
                                    </div>
                                </th>
                                <th ng-click="sort('CommandCode')">MS phiếu
                                <div ng-class="orderBy != 'CommandCode' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')" class="sorting fa">
                                </div>
                                </th>
                                <th ng-click="sort('CreatedName')">N.Viên ĐX
                                <div ng-class="orderBy != 'CreatedName' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')" class="sorting fa">
                                </div>
                                </th>
                                <th ng-click="sort('CreatedDate')">Ngày ĐX
                                <div ng-class="orderBy != 'CreatedDate' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')" class="sorting fa">
                                </div>
                                </th>
                                <th ng-click="sort('Username')">Tài xế
                                <div ng-class="orderBy != 'Username' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')" class="sorting fa">
                                </div>
                                </th>
                                <th ng-click="sort('LicensePlate')">Số xe
                                <div ng-class="orderBy != 'LicensePlate' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')" class="sorting fa">
                                </div>
                                </th>
                                <th ng-click="sort('Date')" class="center">Ngày G/N
                                <div ng-class="orderBy != 'Date' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')"
                                    class="sorting fa">
                                </div>
                                </th>
                                <th ng-click="sort('PlanQty')" class="center">SL
                                <div ng-class="orderBy != 'PlanQty' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')"
                                    class="sorting fa">
                                </div>
                                </th>
                                <th ng-click="sort('ShippedQty')" class="center">Giao
                                <div ng-class="orderBy != 'ShippedQty' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')"
                                    class="sorting fa">
                                </div>
                                </th>
                                <th ng-click="sort('ReceivedQty')" class="center">Nhận
                                <div ng-class="orderBy != 'ReceivedQty' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')"
                                    class="sorting fa">
                                </div>
                                </th>
                                <th ng-click="sort('Status')" class="center">T.Thái
                                <div ng-class="orderBy != 'Status' ? 'fa-sort': (orderDirection == 'ascending' ? 'fa-sort-asc' : 'fa-sort-desc')" class="sorting fa">
                                </div>
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr ng-hide="totalItemOnPage == 0" ng-repeat="item in items" ng-click="setSelected(item.CommandID)"
                                ng-dblclick="edit(item.CommandID)">
                                <td class="center">
                                    <div>
                                        <input ng-click="check(item.CommandID)" ng-model="checkedObj[item.CommandID]" class="center" type="checkbox" />
                                    </div>
                                </td>
                                <td>
                                    @{
                                        var detailurl = Url.Action("Detail", "Command", new { id = "{{id=item.CommandID}}" });
                                        detailurl = HttpUtility.UrlDecode(detailurl);
                                    }
                                    <a data-ng-href="@detailurl">{{item.CommandCode}}</a>
                                </td>
                                <td>{{item.CreatedName}}</td>
                                <td class="center">{{item.CreatedDate | date:'dd/MM/y'}}</td>
                                <td>{{item.UserName}}</td>
                                <td>{{item.LicensePlate}}</td>
                                <td class="center">{{item.Date | date:'dd/MM/y'}}</td>
                                <td>{{item.PlanQty}}</td>
                                <td>{{item.ShippedQty}}</td>
                                <td>{{item.ReceivedQty}}</td>
                                <td>{{statuss[item.Status]}}</td>
                            </tr>
                            <tr ng-show="totalItemOnPage == 0">
                                <td colspan="100">Không có dữ liệu
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </form>
    </div>
</div>
